package com.sky.controller;

import com.sky.domain.WmsWareInfo;
import com.sky.service.WmsWareInfoService;
import com.sky.utils.PageUtils;
import com.sky.utils.R;
import com.sky.vo.param.WareInfoVO;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@RequestMapping("/wareInfo")
public class WmsWareInfoController {

    @Resource
    private WmsWareInfoService wareInfoService;

    @RequestMapping("/page")
    public R page(WareInfoVO vo) {
        PageUtils page = wareInfoService.pageQuery(vo);
        return R.ok(page);
    }

    @GetMapping("/getById/{id}")
    public R getById(@PathVariable("id") Long id) {
        WmsWareInfo wareInfo = wareInfoService.getById(id);
        return R.ok(wareInfo);
    }

    @PostMapping("/save")
    public R save(@RequestBody WareInfoVO vo) {
        WmsWareInfo wareInfo = new WmsWareInfo();
        BeanUtils.copyProperties(vo, wareInfo);
        return wareInfoService.save(wareInfo) ? R.ok() : R.error();
    }

    @PostMapping("/update")
    public R update(@RequestBody WareInfoVO vo) {
        WmsWareInfo wareInfo = new WmsWareInfo();
        BeanUtils.copyProperties(vo, wareInfo);
        return wareInfoService.updateById(wareInfo) ? R.ok() : R.error();
    }

    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] id) {
        return R.ok(wareInfoService.removeByIds(Arrays.asList(id)));
    }
}
